Skip to content

Conversation

@aniketmaurya
Copy link
Collaborator

@aniketmaurya aniketmaurya commented Jun 17, 2025

What does this PR do?

Users can run async API with minimal code:

import litserve as ls

class MinimalAsyncAPI(ls.LitAPI):
    def setup(self, device):
        self.model = None

    async def predict(self, x):
        y = x["input"] ** 2
        return {"output": y}
  • Introduced _handle_async_function to manage the invocation of async and sync functions, improving code clarity.
  • Added tests for _handle_async_function and _async_inject_context to ensure correct behavior and context handling.
Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

- Changed logging level from info to debug in RegularRequestHandler for improved log granularity.
- Refactored `_async_inject_context` in base.py to streamline context injection for async functions.
- Introduced `_handle_async_function` to manage the invocation of async and sync functions, improving code clarity.
- Added tests for `_handle_async_function` and `_async_inject_context` to ensure correct behavior and context handling.
- Introduced a new test file `test_async.py` to validate the behavior of an asynchronous API using the LitServe framework.
- Implemented a minimal async API class and a corresponding test case to ensure correct prediction output for async requests.
- Utilized pytest and httpx for testing the async functionality, ensuring proper handling of requests and responses.
@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85%. Comparing base (550a23e) to head (07c14b9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #553   +/-   ##
===================================
  Coverage    85%    85%           
===================================
  Files        38     38           
  Lines      2940   2942    +2     
===================================
+ Hits       2504   2510    +6     
+ Misses      436    432    -4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@aniketmaurya aniketmaurya merged commit b36d10e into main Jun 17, 2025
21 checks passed
@aniketmaurya aniketmaurya deleted the auto-async branch June 17, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants